import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'function/LoadingDialog.dart';
import 'function/NetLoadingDialog.dart';
import 'module/FunctionDemo.dart';
import 'module/HttpDemo.dart';
import 'module/ProjectWidget.dart';
import 'module/ViewDemo.dart';

class YzhgHomeRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new TabBarDemo();
  }
}

class TabBarDemo extends StatefulWidget {
  @override
  _TabBarDemo createState() => new _TabBarDemo();
}

class _TabBarDemo extends State<TabBarDemo> {
  //设置当前展示的页面
  int _tabIndex = 0;

  //存放三个页面
  var _pageList;

  void initData() {
    //创建三个子页面存放三个widget
    _pageList = [
      new ViewDemo(),
      new FunctionDemo(),
      new HttpDemo(),
      new ProjectWidget()
    ];
  }

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((msg) {
      showDialog<Null>(
          context: context, //BuildContext对象
          barrierDismissible: false,
          builder: (BuildContext context) {
            return new LoadingDialog( //调用对话框
              text: '正在获取详情...',
            );
          });
    });

   // new NetLoadingDialog(outsideDismiss: false);

    /*Future.delayed(Duration.zero, () {
      _showDialog();
    });*/
  }

  _showDialog() {
    showDialog<Null>(
      context: context,
      builder: (BuildContext context) {
        return new SimpleDialog(
          title: new Text('选择'),
          children: <Widget>[
            new SimpleDialogOption(
              child: new Text('选项 1'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            new SimpleDialogOption(
              child: new Text('选项 2'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    ).then((val) {
      print(val);
    });
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334);
    initData();
    return Scaffold(
        appBar: AppBar(
          title: Text("造物之前,必先造人."),
        ),
        // DefaultTextStyle(style: TextStyle(fontSize: 14, color: Colors.blue), child: );
        body: _pageList[_tabIndex],
        bottomNavigationBar: new BottomNavigationBar(
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
                icon: Icon(Icons.home), title: Text('基础控件')),
            BottomNavigationBarItem(
                icon: Icon(Icons.business), title: Text('功能组件')),
            BottomNavigationBarItem(
                icon: Icon(Icons.school), title: Text('网络组件')),
            BottomNavigationBarItem(
                icon: Icon(Icons.school), title: Text('完整APP')),
          ],
          type: BottomNavigationBarType.fixed,
          currentIndex: _tabIndex,
          iconSize: 24.0,
          fixedColor: Colors.blue,
          onTap: _onItemTapped,
        ));
  }

  void _onItemTapped(int index) {
    setState(() {
      _tabIndex = index;
    });
  }
}
